<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'post-form',
        'enableClientValidation'=>true,
        'clientOptions'=>array(
            'validateOnSubmit' => true,
            'validateOnChange' => true,
            'afterValidate' => "js:function(form, data, hasError){
            return postReplyAfterValidate(form, data, hasError);
            }",
        ),
        'enableAjaxValidation'=>false,
        'htmlOptions' => array('class' => 'form-horizontal', 'actionType' => $this->action->id)
    )); ?>

<?php echo $form->errorSummary($model); ?>

<div class="panel panel-simple">
    <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list-alt"></i> Nội dung <span class="panel-under primary"></h3>
    </div>
    <div class="panel-body">
        <div class="form-group">
            <?php echo $form->labelEx($model,'cat_id', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-10"> 
                <?php echo $form->dropDownList($model,'cat_id', PostCat::model()->getDataGroup(), array(
                        'empty' => 'Chọn chuyên mục', 
                        'class' => 'form-control',
                        'options' => PostCat::model()->getDataForOptionTag()
                    )); ?>
                <?php echo $form->error($model,'cat_id');?>
            </div>
        </div>
        <div class="form-group block-toggle" id="block-type">
            <?php echo $form->labelEx($model,'type', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-10">
                <?php echo $form->dropDownList($model,'type', Post::model()->getTypeData(), array('empty' => '', 'class' => 'form-control')); ?>
                <?php echo $form->error($model,'type');?>    
            </div>
        </div>
        <div class="form-group block-toggle" id="block-state">
            <?php echo $form->labelEx($model,'state', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-10">
                <?php echo $form->dropDownList($model,'state', Post::model()->getStateData(), array('empty' => '', 'class' => 'form-control')); ?>
                <?php echo $form->error($model,'state');?>
            </div>
        </div>
        <div class="form-group block-toggle" id="block-area-use">
            <?php echo $form->labelEx($model,'area_use', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-8">
                <div class="input-group">
                    <?php echo $form->textField($model,'area_use',array('maxlength'=>255, 'class' => 'form-control numeric format', 'placeholder' => $model->getAttributeLabel('area_use'))); ?>
                    <span class="input-group-addon fix-width">m<sup>2</sup></span>
                </div>
                <?php echo $form->error($model,'area_use');?>
            </div>
        </div>
        <div class="form-group block-toggle" id="block-area-floor">
            <?php echo $form->labelEx($model,'area_floor', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-8">
                <div class="input-group">
                    <?php echo $form->textField($model,'area_floor',array('maxlength'=>255, 'class' => 'form-control numeric format', 'placeholder' => $model->getAttributeLabel('area_floor'))); ?>
                    <span class="input-group-addon fix-width">m<sup>2</sup></span>
                </div>
                <?php echo $form->error($model,'area_floor');?>
            </div>
        </div>
        <div class="form-group block-toggle" id="block-price">
            <?php echo $form->labelEx($model,'price', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-8">
                <div class="input-group">
                    <?php echo $form->textField($model,'price',array('maxlength'=>255, 'class' => 'form-control numeric format')); ?>
                    <span class="input-group-addon fix-width">VNĐ</span>
                </div>
                <?php echo $form->error($model,'price');?>
            </div>
        </div>
        <div class="form-group">
            <?php echo $form->labelEx($model,'title', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-20">
                <?php echo $form->textField($model,'title', array('maxlength'=>100, 'class' => 'form-control')); ?>
                <?php echo $form->error($model,'title');?>
            </div>
        </div>
        <div class="form-group">
            <?php echo $form->labelEx($model,'content', array('class' => 'col-sm-4 control-label')); ?>
            <div class="col-sm-20">
                <?php echo $form->textArea($model,'content', array('style' => 'height: 300px', 'class' => 'editor')); ?>
                <?php echo $form->error($model,'content');?>
            </div>
        </div>
    </div>
</div>

<div class="panel panel-simple">
    <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-picture-o"></i> Đăng ảnh <span class="panel-under success"></h3>
    </div>
    <div class="panel-body">
        <?php echo $form->error($model,'image', array('style' => 'margin-left: 0px'));?>
        <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
        <div class="row fileupload-buttonbar" style="margin-bottom: 20px;">
            <div class="col-sm-12 col-xs-12">
                <div class="row">
                    <div class="col-md-8 col-sm-24">
                        <span class="btn btn-success fileinput-button">
                            <span><i class="fa fa-upload"></i> Tải ảnh lên</span>
                            <input type="file" name="files[]" multiple>
                        </span> 
                        <?php /*
                            <button type="submit" class="btn btn-primary start">
                            <i class="icon-upload icon-white"></i>
                            <span>Start upload</span>
                            </button>
                            <button type="reset" class="btn btn-warning cancel">
                            <i class="icon-ban-circle icon-white"></i>
                            <span>Cancel upload</span>
                            </button>
                            <button type="button" class="btn btn-danger delete">
                            <i class="icon-trash icon-white"></i>
                            <span>Delete</span>
                            </button>
                            <input type="checkbox" class="toggle">
                        */?>
                    </div>
                    <div class="col-md-16 hidden-sm hidden-xs hidden-sm">
                        Hoặc kéo & thả ảnh vào đây
                    </div>
                </div>

            </div>
            <!-- The global progress information -->
            <div class="col-sm-12 col-xs-12 fileupload-progress fade">
                <!-- The global progress bar -->
                <div class="progress progress-striped active" style="margin: 0;" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                    <div class="bar progress-bar" style="width:0%;"></div>
                </div>
                <!-- The extended global progress information -->
                <?php /*<div class="progress-extended">&nbsp;</div>*/?>
            </div>
        </div>
        <!-- The table listing the files available for upload/download -->
        <div id="upload-grid">
            <table role="presentation" class="table table-striped table-hover table-condensed">
                <tbody class="files"></tbody>
            </table>
        </div>
    </div> 
</div> 

<div class="row" id="block-address">
    <div class="col-sm-10">

        <div class="panel panel-simple">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-home"></i> Địa chỉ <span class="panel-under danger"></h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <?php echo $form->labelEx($model,'city_id', array('class' => 'col-sm-8 control-label')); ?>
                    <div class="col-sm-16">
                        <?php echo $form->dropDownList($model,'city_id', City::model()->data, array('class' => 'form-control', 'empty' => 'Chọn thành phố')); ?>
                        <?php echo $form->error($model,'city_id');?>
                    </div>
                </div>
                <div class="form-group">
                    <?php echo $form->labelEx($model,'district_id', array('class' => 'col-sm-8 control-label')); ?>
                    <div class="col-sm-16">
                        <?php echo $form->dropDownList($model,'district_id', $district_data, array('empty' => '', 'class' => 'form-control')); ?>
                        <?php echo $form->error($model,'district_id');?>
                    </div>
                </div>  
                <div class="form-group">
                    <?php echo $form->labelEx($model,'address', array('class' => 'col-sm-8 control-label')); ?>
                    <div class="col-sm-16">
                        <?php echo $form->textField($model,'address',array('maxlength'=>255, 'class' => 'form-control')); ?>
                        <?php echo $form->error($model,'address');?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-8 control-label">Địa chỉ đầy đủ</label>
                    <div class="col-sm-16">
                        <textarea id="address_full" class="form-control" readonly="readonly" rows="2" style="resize: none;"></textarea>
                    </div>
                </div> 
                <div class="form-group">
                    <?php echo $form->labelEx($model,'latlng', array('class' => 'col-sm-8 control-label')); ?>
                    <div class="col-sm-16">
                        <?php echo $form->textField($model,'latlng',array('readonly' => 'readonly','maxlength'=>255, 'class' => 'form-control')); ?>
                        <?php echo $form->error($model,'latlng');?>
                    </div>
                </div> 
                <div class="form-group">
                    <div class="col-sm-offset-8 col-sm-16">
                        <?php echo $form->checkBox($model,'show_map'); ?>
                        <?php echo $form->labelEx($model,'show_map'); ?>
                    </div>

                    <div class="col-sm-offset-8 col-sm-16">
                        <?php echo $form->checkBox($model,'is_all_city'); ?>
                        <?php echo $form->labelEx($model,'is_all_city'); ?>
                        <abbr class="initialism" rel="tooltip" title="" data-original-title="Rao tin này trên toàn quốc">
                            <i class="fa fa-question-circle"></i>
                        </abbr>
                    </div>
                </div> 
            </div> 
        </div> 

    </div>
    <div class="col-sm-14">
        <div class="panel panel-simple">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-map-marker"></i> Bản đồ 
                    <small><i>(kéo thả <abbr title="Tọa độ của lá cờ là tọa độ địa chỉ của bạn trên bản đồ" rel="tooltip"><img style="height: 18px; vertical-align: 0px;" src="/files/img/red_flag.png"/></abbr> để chọn tọa độ)</i></small> 
                    <span class="panel-under info"></span>
                </h3>
            </div>
            <div class="panel-body">
                <div id="map" class="well" style="width: 100%; height: 330px; margin: 0;">
                    <div style="color: #999999; height: 290px; padding-top: 90px;">
                        <ol>
                            <li>Chọn thành phố, quận huyện để hiển thị bản đồ</li>
                            <li>Chọn tọa độ cho địa chỉ của bạn</li>
                        </ol>
                    </div>
                </div> 
            </div> 
        </div> 

    </div>
</div>

<?php if(!$model->isNewRecord):?>
    <div class="form-group">
        <?php echo $form->labelEx($model,'status', array('class' => 'col-sm-10 control-label')); ?>
        <div class="col-sm-6">
            <?php echo $form->dropDownList($model,'status', Post::model()->getStatusData(), array('class' => 'form-control')); ?>
            <?php echo $form->error($model,'status');?>
        </div>
    </div>
    <?php endif?>

<div class="form-group">
    <div class="col-sm-offset-10 col-sm-14">
        <button class="btn btn-primary btn-lg" type="submit">
            <?php if($model->isNewRecord):?>
                <i class="fa fa-pencil-square-o"></i> Đăng bài
                <?php else:?>
                <i class="fa fa-pencil-square-o"></i> Sửa bài
                <?php endif?>
        </button>        
    </div>
</div>
<?php $this->endWidget(); ?>

<?php $this->renderPartial('_upload_require')?>


<script>var post_upload_url = '<?php 

    $params = array('type' => 'post'); 
    if($model->id) $params['id'] = $model->id; 
    if($this->action->id == 'create' && $coverSaved) $params['cover'] = $coverSaved; 
    echo $this->createUrl('/hangve/post/upload', $params);

?>';</script>

<script type="text/javascript" src="<?php echo $this->googleMapURI?>"></script> 
<script>
    var citiesRefID = <?php echo json_encode(City::model()->getDataRefById())?>;
    var districtsRefID = <?php echo json_encode(District::model()->getDataRefByKey('id'))?>;
    var districtDataGroupByCityId = <?php echo json_encode(District::model()->getDataGroupByCity())?>;
    var postAction = '<?php echo $this->action->id?>';
    <?php if(!(string)Yii::app()->request->cookies['post_saved']):?> 
        if(typeof(Storage)!=="undefined"){
            delete localStorage.post_content;
        }
        <?php endif?>
</script>
<script type="text/javascript" src="/files/editor/tinymce4/tinymce.min.js"></script>
<script type="text/javascript" src="<?php echo $this->themeUrl?>/files/js/post_form.js"></script> 
